.. This file was automatically converted from MediaWiki syntax. If some markup is wrong, looks weird or doesn't make sense, feel free to fix it. Please remove this comment once this file was manually checked and no "strange ReST" artifacts remain. .. _the-window-framework: The Window Framework ==================== .. only:: python The WindowFramework class is for use in C++ only. If you use Python, you can just use DirectStart to open a window and skip this page. .. only:: cxx This page will explain how to use the WindowFramework class in C++ to open a blank window. First of all, we need to include the appropriate header files: .. code-block:: cpp #include "pandaFramework.h" #include "pandaSystem.h" Second, we need to create an instance of the WindowFramework class and open the main int of course. .. code-block:: cpp PandaFramework framework; int main(int argc, char *argv[]) { Now, we must open the framework, give the window a nice title and open the window: .. code-block:: cpp framework.open_framework(argc, argv); framework.set_window_title("Hello World!"); // Open it! WindowFramework *window = framework.open_window(); Optionally, we can enable keyboard support, in case we want to check for keyboard presses, and we can enable the default camera trackball. Note that you also need to enable keyboard support to receive mouse button events (sic). .. code-block:: cpp // Enable keyboard detection window->enable_keyboard(); // Enable default camera movement window->setup_trackball(); Now, we're going to check if the window has opened successfully. If so, the main loop must be called, using the function framework.main\_loop(). This is equal to the run() function in Python. .. code-block:: cpp if (window != (WindowFramework *)NULL) { nout << "Opened the window successfully!\n"; // Put here your own code, such as the loading of your models framework.main_loop(); } else { nout << "Could not load the window!\n"; } Afterwards, we need to close the framework: .. code-block:: cpp framework.close_framework(); return (0); } Now, :ref:`compile and run ` your file and you have your own window opened! For the lazy ones among us, here is the full code: .. code-block:: cpp // Include all the stuff #include "pandaFramework.h" #include "pandaSystem.h" // Init the PandaFramework class PandaFramework framework; int main(int argc, char *argv[]) { // Open the framework framework.open_framework(argc, argv); // Set a nice title framework.set_window_title("Hello World!"); // Open it! WindowFramework *window = framework.open_window(); // Check whether the window is loaded correctly if (window != (WindowFramework *)NULL) { nout << "Opened the window successfully!\n"; window->enable_keyboard(); // Enable keyboard detection window->setup_trackball(); // Enable default camera movement // Put here your own code, such as the loading of your models // Do the main loop framework.main_loop(); } else { nout << "Could not load the window!\n"; } // Close the framework framework.close_framework(); return (0); } The WindowFramework class also provides all the basic things the python ShowBase / DirectStart equivalent would normally take care of: .. code-block:: cpp const NodePath &get_render(); const NodePath &get_render_2d(); const NodePath &get_aspect_2d(); void set_wireframe(bool enable); void set_texture(bool enable); void set_two_sided(bool enable); void set_one_sided_reverse(bool enable); void set_lighting(bool enable); const NodePath &get_camera_group(); INLINE int get_num_cameras() const; INLINE Camera *get_camera(int n) const; // WindowFramework also provides access to the GraphicsWindow. // for example, to set the background color to black, you can do this: window->get_graphics_window()->set_clear_color(Colorf(0,0,0,1)); It's very useful to study the file panda/src/framework/windowFramework.h, since you will need to use it often.